import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/stores'
//导入登录页面组件
import Login from '@/views/login/Login.vue'
//导入教师页面相关组件
import TeacherHome from '@/views/teacher/TeacherHome.vue'
import TeachingProject from '@/views/teacher/TeachingProject.vue'
//导入教秘页面相关组件
import SecretaryHome from '@/views/secretary/SecretaryHome.vue'
import CheckTeachingProject from '@/views/secretary/CheckTeachingProject.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes:[
    //登录页面路由配置
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    //教师页面路由配置
    { path: '/teacher-home', redirect: '/teacher-home/teachingProject', component: TeacherHome, children: [
        {path: 'teachingProject', component: TeachingProject, name: 'teachingProject'},
      ]},
    //教秘页面路由配置
    { path: '/secretary-home',redirect: '/secretary-home/checkTeachingProject', component: SecretaryHome, children: [
        { path: 'checkTeachingProject', component: CheckTeachingProject, name: 'checkTeachingProject'},
      ]}
  ]
})
//登录访问拦截 => 默认是直接方形的
//根据返回值决定，是放行还是拦截
//返回值：
//1.undefined / true 直接放行
//2.false 拦回from的地址页面
//3.具体路径 或 路径对象 拦截到对应的地址
// '/login'  { name: 'login }
router.beforeEach((to) => {
  // 如果没有token，且访问的是非登录页，拦截到登录，其他情况正常放行
  const useStore = useUserStore()
  //没有忘记密码时
  // if(!useStore.token && to.path !== '/login' && to.path !== '/register')return '/login'
})
export default router
